<%-- <%@page import="domain.DAOFactory"%> --%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="domain.entities.interfaces.*"%>
<%@ page import="domain.dao.interfaces.*"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.springframework.context.support.ClassPathXmlApplicationContext"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<%@ taglib prefix="bean" uri="http://struts.apache.org/tags-bean"%>
<%@ taglib prefix="nested" uri="http://struts.apache.org/tags-nested"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
	"http://www.w3.org/TR/html4/loose.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="../css/bootstrap.css">
<title>Remove contact from group</title>
<link rel="stylesheet" type="text/css" href="/mdoc-project/css/bootstrap_Boris.css">
<base href="<%=request.getScheme()%>://<%=request.getServerName()%>:<%=request.getServerPort()%><%=request.getContextPath()%>/">
</head>
<body>

	<%
		boolean connected = session
				.getAttribute(DomainUtils.CURRENT_USER_STRING) != null;

		ApplicationContext context = null;
		String strIdContactGroup = null;
		int idContactGroup = -1;

		IDAOContactGroup daoContactGroup = null;
		IContactGroup cg = null;

		if (connected == true) {
			context = util.SpringUtils.getApplicationContext();
			strIdContactGroup = request
					.getParameter("selected_contactgroup");
			idContactGroup = Integer.parseInt(strIdContactGroup);

			daoContactGroup = (IDAOContactGroup) context
					.getBean("beanDAOContactGroup");
			cg = daoContactGroup.getById(idContactGroup);
		}

		if (connected == false) {
			request.setAttribute(DomainUtils.ALERT_ERROR_STRING,
					"You must be connected");
		} else if (cg == null) {
			request.setAttribute(DomainUtils.ALERT_ERROR_STRING,
					"This contact group has been deleted.");
		}
	%>

	<%@include file="/pages/common_style/header.jsp"%>
	<%@include file="/pages/common_style/alerts.jsp"%>

	<%
		if (connected) {
	%>

	<html:form action="/RemoveFromContactGroup">
		<html:errors />
		<div class="form-group">
			<label for="included_contacts">Choose contacts to remove</label>
			<div class="form-control" id="included_contacts" style="overflow: scroll; height: 150px;">

				<%
					if (cg != null) {
								String options = "";

								for (IContact c : daoContactGroup
										.getContainedContact(idContactGroup)) {
									options += "<input type=\"checkbox\" name=\"contacts_to_remove\" id=\"chbx_"
											+ c.getId()
											+ "\" value=\""
											+ c.getId()
											+ "\"/>"
											+ "<label for=\"chbx_"
											+ c.getId()
											+ "\">"
											+ DomainUtils.displayContact(c)
											+ "</label><br>";
								}
				%>
				<%=options%>
				<%
					}
				%>
			</div>
		</div>
		<input type="hidden" name="selected_contactgroup" value="<%=strIdContactGroup%>">
		<br>
		<button type="submit" class="btn btn-default">Submit</button>
		<button type="reset" class="btn btn-default">Reset</button>
	</html:form>


	<br>
	<a class="btn btn-default navbar-btn" href="pages/showAllContactGroups.jsp">Return</a>

	<%
		}
	%>

	<%@include file="/pages/common_style/footer.jsp"%>
</body>
</html>